<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>title</title>
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../css/public.css" />
    <style>
        .footer_web {
            width: 100%;
            height: 60px;
            background: #bbb;
            color: #fff;
            position: fixed;
            left: 0;
            bottom: 0;
            margin: 0 auto;
            text-align: center;
        }

        .footer_web.active {
            background: -webkit-linear-gradient(left, #ff9301, #ff2625);
        }

        .footer_web span {
            width: 50%;
            height: 60px;
            line-height: 60px;
            text-align: center;
            font-size: 13px;
        }
    </style>
</head>

<body>
    <header class="aui-bar aui-bar-nav  aui-bg-tag-money" id='aui-header'>
        <a class="aui-pull-left aui-btn" tapmode onclick="webGoBack();"> <span class="aui-iconfont aui-icon-left"></span> </a>
        <div class="aui-title" id="name"></div>
        <a class="aui-btn aui-pull-right" tapmode onclick="api.closeWin();">
            <span class="aui-iconfont aui-icon-close"></span>
        </a>
    </header>
    <div class="footer_web active" id="detailfooter" style="display: block;">
        <span id="title">打开商品页查看可省金额</span>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/config.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript" src="../script/zepto.min.js"></script>
<script type="text/javascript" src="../script/phpSerializer.js"></script>
<script type="text/javascript" src="../script/utf.js"></script>
<script type="text/javascript">
    var pageParam = {};
    var userinfo;
    apiready = function() {
        pageParam = api.pageParam;
        if (pageParam.data) {
            pageParam = pageParam.data;
        }
        var header = $api.byId('aui-header');
        $api.fixStatusBar(header);
        var headerPos = $api.offset(header).h;
        userinfo = isLoginOr();
        openWinX5({
            y: headerPos,
            url: pageParam.url,
            marginBottom: 60
        }, function(ret, err) {

            if (ret.title) {
                $(".aui-title").text(ret.title);
            }
            if (ret.state == 0) {
                var platform = checkurlPlatform(ret.url);
                var itemid = "";
                if (platform == 'tb' || platform == 'jd' || platform == 'pdd' || platform == 'sn' || platform == 'vip' || platform == 'mgj') {
                    itemid = getGoodId(platform, ret.url);
                    if (itemid !== "") {
                        console.log("检测到：" + platform + ":" + itemid);
                        $("#title").text("可赚金额计算中……");
                        getGoodDetail({
                            apiname: 'goodsDetail',
                            source_type: platform,
                            goods_id: itemid
                        }, function(ret, err) {
                            console.log(JSON.stringify(ret));
                            if (ret) {
                                if ((ret.code == 1 || ret.status_code == 200) && ret.data != '') {
                                    $(".footer_web").addClass("active");
                                    $("#detailfooter").show();
                                    var s_money = ret.data.commission;
                                    s_money = parseFloat(s_money).toFixed(2);
                                    if (userinfo) {
                                        s_money = (s_money * userinfo.yjrate * 0.01).toFixed(2);
                                    }
                                    if (platform === 'sn') {
                                        $("#title").text("该商品有可赚金额");
                                        openWinto('detail_win', 'widget://html/good_pdd_jd_detail_win', {
                                            gooditem: JSON.stringify({
                                                goodid: ret.data.goodid,
                                                sellerid: ret.data.sellerid,
                                                yj: ret.data.yj
                                            })
                                        });
                                    } else if (platform === 'vip') {
                                        $("#title").text("自购省￥" + s_money);
                                        ret.data.formwin = 'web_view_win';
                                        openWinto('detail_win', 'widget://html/good_pdd_jd_detail_win', ret.data);
                                    } else if (platform === 'mgj') {
                                        $("#title").text("自购省￥" + s_money);
                                        ret.data.formwin = 'web_view_win';
                                        openWinto('detail_win', 'widget://html/good_pdd_jd_detail_win', ret.data);
                                    } else {
                                        openWinto('detail_win', 'widget://html/good_pdd_jd_detail_win', {
                                            gooditem: JSON.stringify(ret.data)
                                        });
                                    }
                                    if (ret.state == 2) {
                                        api.execScript({
                                            name: 'web_view_win',
                                            script: "webGoBack()"
                                        });
                                    }

                                } else {
                                    $(".footer_web").removeClass("active");
                                    $("#title").text("未检测到参与推广的商品");
                                }
                            } else {
                                showToast('获取数据错误~');
                            }

                        });
                    } else {
                        $("#title").text("打开商品页查看可省金额");
                    }
                }
            }
        });

        api.addEventListener({
            name: 'keyback'
        }, function(ret, err) {
            var browser = api.require('webBrowser');
            browser.historyBack(
                function(ret, err) {
                    if (!ret.status) {
                        api.closeWin();
                    }
                }
            );
        });
    };
</script>

</html>
